import Vue from 'vue'
import VueRouter from 'vue-router'
import Name from './Name'
import User from './User'
import Edu from './Edu'
import Loss from './Loss'
import Secondary from './Secondary'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Name',
        component: Name
    },
    {
        path: '/user',
        name: 'User',
        component: User,
        alias:"/kiss",//别名
        children:[
            {
                path:'',
                component: Secondary
            }
        ]
    },
    // {
    //     path: '/edu/:name/:age', //配置路由独享守卫
    //     name: 'Edu',
    //     component: Edu,
    //     beforeEnter: (to, from, next) => {
    //         console.log(to)
    //         console.log(from)
    //         console.log('路由独享守卫')
    //         next()
    //     }
    // },
    // {
    //     path: '/edu/:name/:age', //重定向
    //     name: 'Edu',
    //     component: Edu,
    //     redirect:"/user"//重定向
    // },
    {
        path: '/edu/:id/:age',
        name: 'Edu',
        component: Edu,
    },
    {
        path: '*',//当没有访问地址时
        name: 'Loss',
        component: Loss
    },
]

const router = new VueRouter({
    routes
})

// router.beforeEach((to,from,next)=>{ //路由前置守卫
//     console.log(to)//进入目标路由
//     console.log(from)//离开的目标路由
//     console.log('路由前置守卫')
//     next()//管道钩子
// })

// router.beforeResolve((to,from,next)=>{ //全局解析守卫
//     console.log(to)//进入目标路由
//     console.log(from)//离开的目标路由
//     console.log('全局解析守卫')
//     next()//管道钩子
// })

// router.afterEach((to,from,next)=>{ //全局后置钩子
//     // console.log(to)//进入目标路由
//     // console.log(from)//离开的目标路由
//     // console.log('全局后置钩子')
//     // next()//管道钩子
// })

export default router